package com.example.sunmiv1.adapter;


import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.ClassificationBean;
import com.example.sunmiv1.entity.ClassifyInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TwoExpandAdapter extends BaseExpandableListAdapter {
    private List<ClassificationBean.GoodscateBean.ChildBeanX> oneList;
    private Context context;
    private LayoutInflater inflater;

    public TwoExpandAdapter(Context context, List<ClassificationBean.GoodscateBean.ChildBeanX> oneList) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.oneList = oneList;
        //this.twoList = twoList;
    }

    @Override
    public int getGroupCount() {
        return oneList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return oneList.get(i).getChild().size();
    }

    @Override
    public Object getGroup(int i) {
        return oneList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return oneList.get(i).getChild().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        GroupViewHolder gvh;
        if (view == null) {
            view = inflater.inflate(R.layout.one_classify_item, null);
            gvh = new GroupViewHolder(view);
            view.setTag(gvh);
        } else {
            gvh = (GroupViewHolder) view.getTag();
        }
        gvh.childChildTV.setText(oneList.get(i).getClass_name());
        gvh.childChildTV.setTextColor(Color.parseColor("#333333"));
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        ChildViewHolder cvh;
        if (view == null) {
            view = inflater.inflate(R.layout.two_classify_item, null);
            cvh = new ChildViewHolder(view);
            view.setTag(cvh);
        } else {
            cvh = (ChildViewHolder) view.getTag();
        }
        cvh.childChildTV.setText(oneList.get(i).getChild().get(i1).getClass_name());
        cvh.childChildTV.setTextColor(Color.parseColor("#333333"));
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    static class GroupViewHolder {
        @BindView(R.id.childChildTV)
        TextView childChildTV;

        GroupViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static class ChildViewHolder {
        @BindView(R.id.childChildTV)
        TextView childChildTV;

        ChildViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
